functor Mir (S: MIR_STRUCTS) = 
struct
  open S
  
  structure I = Ir

  datatype mir_aop 
    = PLUS 
    | MINUS
    | MUL
    | DIV
    | MOD
    | AND
    | OR
      
  datatype mir_cop
    = NE  
    | EQ  
    | LE
    | LT
    | GE
    | GT

  datatype mir_exp 
    = DUMMY
    | CONST of int
    | PCONST of I.mytype 
    | NAME of string
    | TEMP of string * (mir_lnode list) 
    | BINOP of mir_aop * mir_exp * mir_exp 
    | UOP of mir_exp 
    | MEM of mir_exp * int
    | CALL of string * (mir_exp list)

    | ARRAYEX of mir_exp * int 
    | PTREX of mir_exp * int 

  and mir_lnode
    = Label of string * int
    | JMP of string
    | CJMP of mir_cop * mir_exp * mir_exp * string * string
    | EXP of mir_exp
    | MOV of mir_exp * mir_exp

  type mir_fun = mir_lnode list

  type mir_data = (string * int) list 
  
  val lbinfs : (int * I.exp option) list ref = ref [(0, NONE)]

  val tmpNum : int ref = ref 1
  fun genTmp() =
      let val t = !tmpNum
	  val _ = tmpNum := !tmpNum + 1
      in t
      end

  fun newLbInf a = 
      let val t = genTmp()
	  val _ = lbinfs := (t, SOME(a))::(!lbinfs)
      in t
      end

  fun getLbInf lbi = 
      let fun fdlbi ((lb, t), r) = if lb = lbi
				     then t
				     else r
	  val res = List.foldl fdlbi NONE (!lbinfs)
      in res
      end

end
